package fun.qu_an.minecraft.voicechatplugin.mixin.tick_stasis;

import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager;
import de.maxhenkel.voicechat.voice.server.ServerVoiceEvents;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.function.Consumer;

@Mixin(ServerVoiceEvents.class)
public abstract class ServerVoiceEventsMixin {
	@Redirect(method = "<init>()V",
		remap = false,
		at = @At(value = "INVOKE", target = "Lde/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager;onServerStarting(Ljava/util/function/Consumer;)V"))
	private void onRegisterServerStarting(CommonCompatibilityManager instance, Consumer<MinecraftServer> minecraftServerConsumer) {
		instance.onServerStarting(server -> {
			if (!server.getPlayerManager().getPlayerList().isEmpty()) {
				minecraftServerConsumer.accept(server);
			}
		});
	}
}
